import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
Vue.use(VueRouter)

const routes = [
  // {
  //   path: '/',
  //   redirect: '/login'
  // },
  {
    path: '/',
    component: () => import('../components/Home1'),
    children: [
      {
        title: '首页',
        path: 'home',
        name: 'home',
        component: () => import('../views/home/Home')
      },
      {
        path: '/biosample/project',
        component: () => import('../views/Biosanple')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login')
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  const token = window.sessionStorage.getItem('token')
  if (to.path === '/login') return next()
  if (!token) return next('/login')
  next()
  // if (to.meta.title) { // 如果设置标题，拦截后设置标题
  //   document.title = to.meta.title
  // }

  // if (to.path !== '/login') {
  //   if (!store.getters.isLogin) {
  //     Message.error('请先登录')
  //     next('/login')
  //     return
  //   }
  //   // 判断是否需要添加到tabs标签
  //   if (to.meta.isTabsPage) {
  //     const tabsItem = {
  //       name: to.name,
  //       title: to.meta.title,
  //       path: to.path
  //     }
  //     store.commit('ADD_TABS_VALUE', tabsItem)
  //   }
  // }
  // next()
})

export default router
